package cn.sh.ideal.web.view.display.oracle.monitor.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;


/**  
* @Description: oracle监控页面数据访问
* @author zhangyy  
* @date 2018年6月5日  
*/
@Controller
@RequestMapping(value = "/data")
@PropertySource(value = { "classpath:jdbc.properties" })
public class OracleMonitorDataController {

	@Bean
	public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
		return new PropertySourcesPlaceholderConfigurer();
	}

	private RestTemplate rs = new RestTemplate();

	@Value("${server_address}")
	private String serverAddress;


	/**
	 * 查询获取原系统主机信息角色
	 * @param request
	 * @return result
	 * 前端ajax： contentType 默认不设定  request.getParameter可以获取参数
	 * get  方式向monitorCenter项目发出请求 参数以拼接方式传递 	@GetMapping("/getRoles") 接收
	 */
	@RequestMapping(value = "/selectOracleMonitorInfo", method = RequestMethod.POST)
	@ResponseBody
	public String selectOracleMonitorInfo(HttpServletRequest request,HttpServletResponse response) {

		Integer size = Integer.valueOf(request.getParameter("size"));
		Integer page = Integer.valueOf(request.getParameter("page"));
		String hostName = request.getParameter("hostName");
		String systemName = request.getParameter("systemName");

		StringBuffer url =new StringBuffer(serverAddress);
		url.append("/selectOracleMonitorInfo?size=").append(size).append("&page=").append(page)
		.append("&hostName=").append(hostName).append("&systemName=").append(systemName);
		HttpHeaders headers = new HttpHeaders();
		MediaType type = MediaType
				.parseMediaType("application/json;charset=UTF-8");
		headers.setContentType(type);
		HttpEntity<String> entity = new HttpEntity<>(new String(), headers);

		ResponseEntity<String> exchange = rs.exchange(url.toString(), HttpMethod.GET,
				entity, String.class);

		String reult = exchange.getBody();
		return reult;
}
}
